home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / ldiv.c,v < prev    next >
Encoding:
Text File  |  1989-03-22  |  2.0 KB  |  104 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.03.22.00.47.18;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     88.05.21.12.14.44;  author ouster;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @*** empty log message ***
  27. @
  28. text
  29. @/* 
  30.  * ldiv.c --
  31.  *
  32.  *    Contains the source code for the "ldiv" library procedure.
  33.  *
  34.  * Copyright 1988 Regents of the University of California
  35.  * Permission to use, copy, modify, and distribute this
  36.  * software and its documentation for any purpose and without
  37.  * fee is hereby granted, provided that the above copyright
  38.  * notice appear in all copies.  The University of California
  39.  * makes no representations about the suitability of this
  40.  * software for any purpose.  It is provided "as is" without
  41.  * express or implied warranty.
  42.  */
  43.  
  44. #ifndef lint
  45. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/ldiv.c,v 1.1 88/05/21 12:14:44 ouster Exp Locker: rab $ SPRITE (Berkeley)";
  46. #endif /* not lint */
  47.  
  48. #include <stdlib.h>
  49.  
  50. /*
  51.  *----------------------------------------------------------------------
  52.  *
  53.  * ldiv --
  54.  *
  55.  *    Compute the quotient and remainder of the division of numer
  56.  *    by denom.
  57.  *
  58.  * Results:
  59.  *    The return value is j, unless j is negative, in which case
  60.  *    the return value is -j.
  61.  *
  62.  * Side effects:
  63.  *    None.
  64.  *
  65.  *----------------------------------------------------------------------
  66.  */
  67.  
  68. ldiv_t
  69. ldiv(numer, denom)
  70.     long int numer;            /* Number to divide into. */
  71.     long int denom;            /* Number that's divided into it. */
  72. {
  73.     ldiv_t result;
  74.  
  75.     result.quot = numer/denom;
  76.     result.rem = numer%denom;
  77.     if ((result.rem ^ numer) < 0) {
  78.     if (result.rem < 0) {
  79.         result.rem += denom;
  80.         result.quot -= 1;
  81.     } else {
  82.         result.rem -= denom;
  83.         result.quot += 1;
  84.     }
  85.    }
  86.    return result;
  87. }
  88. @
  89.  
  90.  
  91. 1.1
  92. log
  93. @Initial revision
  94. @
  95. text
  96. @d17 2
  97. a18 2
  98. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  99. #endif not lint
  100. d20 1
  101. a20 1
  102. #include "stdlib.h"
  103. @
  104.